package com.baijiayun.liveuibase.base;

import android.os.Environment;

import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.Nullable;

import java.io.File;

public class BaseUIConstant {
    // 上传失败自定义错误码
    public static final int ERROR_CODE_UPLOAD_FAIL_CANT_REUPLOAD_CUSTOM_CODE = -1;
    // 作业下载文件夹
    public static final String homeworkDirPath = Environment.getExternalStorageDirectory() + File.separator
            + "homework/";

    /**
     * toolbar 事件发生来源
     */
    public enum SelectSrc {
        Brush,
        Marker,
        Graph,
        Text
    }

    /**
     * 上传文件类型
     */
    public enum UploadType {
        AnimDoc(10),
        StaticDoc(11),
        HomeWork(12),
        AnimCloudFile(13),
        StaticCloudFile(14),
        TransferFromChatImg(15);

        /**
         * i 值不可随意设定
         * 在 GroupClassActivity#onActivityResult 中有使用
         * @see UploadType#containsValue(int)
         */
        int value;

        UploadType(int value) {
            this.value = value;
        }

        public int getValue() {
            return value;
        }

        public static UploadType valueOf(int value) {
            for (int i = 0; i < UploadType.values().length; i++) {
                if (value == UploadType.values()[i].value) {
                    return UploadType.values()[i];
                }
            }
            return null;
        }

        /**
         * 检查 value 在当前 UploadType 中是否存在
         */
        public static boolean containsValue(int value) {
            for (int i = 0; i < UploadType.values().length; i++) {
                if (value == UploadType.values()[i].value) {
                    return true;
                }
            }
            return false;
        }
    }

    public enum ResStateType {
        enable(android.R.attr.state_enabled, 1),
        selected(android.R.attr.state_selected, 2),
        pressed(android.R.attr.state_pressed, 3);

        int state;
        int type;

        ResStateType(int state, int type) {
            this.state = state;
            this.type = type;
        }

        public int getState() {
            return state;
        }

        /**
         * 通过 type 来获取一个对象
         * @Warning type 值 与 attr 中 stateType 的 value 保持一致！！！
         */
        @Nullable
        @Contract(pure = true)
        public static ResStateType valueOf(int type) {
            for (ResStateType stateType : values()) {
                if (stateType.type == type) {
                    return stateType;
                }
            }
            return null;
        }
    }

    /**
     * 文件上传状态
     */
    public enum FileUploadState {
        Uploading(0),
        Translating(1),
        TranslateFailed(2),
        UploadSuccess(3),
        UploadFailed(4);

        int mState;

        FileUploadState(int state) {
            mState = state;
        }

        public boolean isFailed() {
            return this.mState == TranslateFailed.mState || this.mState == UploadFailed.mState;
        }
    }

    /** 作业下载状态 */
    public enum HomeworkDownloadState {
        /** 已下载 */
        HasDownload,
        /** 下载中 */
        Downloading,
        /** 不存在，也不在下载中 */
        NotExit,
        /** 下载失败 */
        DownloadFailed
    }

    /** 列表状态 */
    public enum ListState {
        /** 空 */
        Empty,
        /** 请求中，等待结果 */
        Requesting,
        /** 不为空 */
        NotEmpty
    }
}
